package com.enjoylearning.content.feignClient.fallBack;

import com.enjoylearning.content.feignClient.MediaServiceClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Component
public class MediaServiceClientFallbackFactory implements FallbackFactory<MediaServiceClient> {
    @Override                     //拿到了熔断时的异常信息
    public MediaServiceClient create(Throwable throwable) {

        return new MediaServiceClient() {
            //发生熔断，上游服务调用此方法执行降级逻辑
            @Override
            public String upload(MultipartFile upload, String objectName) {
                log.debug("发生熔断，异常信息：{}", throwable.toString(),throwable);
                return "服务异常，请稍后再试";
            }
        };
    }
}
